using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

using WRM.Windows.Forms;

namespace PropertyTree.Demo
{
	/// <summary>
	/// Summary description for PropertyPane.
	/// </summary>
	public class SharedPane : SharedPropertyPane
	{
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.TextBox textBox1;
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public SharedPane()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

			// TODO: Add any initialization after the InitForm call

		}

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

    /// <summary>
    ///   This is called when the user selects a new SharedPropertyPane to update
    /// the instance data.
    /// </summary>
    /// <remarks>
    ///   This method is called after OnPaneActivating/OnPaneActivated or 
    /// OnPaneDeactivating/OnPaneDeactivated.
    /// </remarks>
    /// <param name="pi">
    /// The <see cref="PaneNode"/> of the node that has just been clicked on.
    /// </param>
    public override void OnPaneInstanceChanged(PaneNode paneNode)
    {
      // It's VERY important to first call the base class's version!
      base.OnPaneInstanceChanged(paneNode);
    
        PaneNodeData pnd = (PaneNodeData)paneNode.Data;
        textBox1.Text = pnd.MyString;
    }


		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.label1 = new System.Windows.Forms.Label();
            this.textBox1 = new System.Windows.Forms.TextBox();
            ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
                | System.Windows.Forms.AnchorStyles.Right);
            this.label1.Location = new System.Drawing.Point(8, 8);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(408, 108);
            this.label1.TabIndex = 0;
            this.label1.Text = @"This is a SharedPropertyPane-derived class.  It is designed so that only one instance of it is ever created - the PropertyTree takes care of handing it different data depending on which node is selected.  This particular implementation simply keeps a string as the shared data.  You can edit the string in the text box below.  Notice that the editted string is switched out as you select different nodes in the PropertyTree.";
            // 
            // textBox1
            // 
            this.textBox1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
                | System.Windows.Forms.AnchorStyles.Left) 
                | System.Windows.Forms.AnchorStyles.Right);
            this.textBox1.Location = new System.Drawing.Point(8, 124);
            this.textBox1.Multiline = true;
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(408, 208);
            this.textBox1.TabIndex = 1;
            this.textBox1.Text = "";
            // 
            // SharedPane
            // 
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.textBox1,
                                                                          this.label1});
            this.Name = "SharedPane";
            this.Size = new System.Drawing.Size(424, 340);
            ((System.ComponentModel.ISupportInitialize)(this)).EndInit();
            this.ResumeLayout(false);

        }
		#endregion

        public override void OnPaneDeactivating(WRM.Windows.Forms.PropertyTree sender, WRM.Windows.Forms.PaneSelectionEventArgs psea)
        {
            // Save the string we were working on...
            PaneNodeData pnd = (PaneNodeData)PaneNode.Data;
            pnd.MyString = textBox1.Text;
        }
	}

    public class PaneNodeData
    {
        private string mString = "";

        public string MyString
        {
            get
            {
                return mString;
            }
            set
            {
                mString = value;
            }
        }
    }
}
